import React, { useEffect, useState, useMemo } from "react";
import { getshoplist } from "../../api";
import { Popconfirm, Space, Table, Tag } from "antd";
import type { TableProps } from "antd";
import { editshoplist } from "../../api";
import dayjs from "dayjs";
interface DataType {
  key: string;
  name: string;
  age: number;
  address: string;
  tags: string[];
}
const Typelist: React.FC = () => {
  let [datalist, getdatalist] = useState([]);
  const getShoplist = async () => {
    let title = await getshoplist();
    let data = title.data.filter((item: any) => {
      if (item.status == true) {
        return item
      }
    });
    getdatalist(data);
  };
  useEffect(() => {
    getShoplist();
  }, []);

  const columns: TableProps<DataType>["columns"] = [
    {
      title: "优惠劵名称",
      dataIndex: "couponName",
    },
    {
      title: "优惠劵面值",
      dataIndex: "discountAmount",
    },
    {
      title: "优惠券最低消费",
      dataIndex: "minSpend",
    },
    {
      title: "优惠券有效期限",
      dataIndex: "validityPeriod",
    },
    {
      title: "排序",
      dataIndex: "sortOrder",
    },
    {
      title: "状态",
      dataIndex: "status",
      render: (status) => {
        return (
          <Tag
            bordered={status ? true : false}
            color={status ? "processing" : "error"}
          >
            {status ? "开启" : "结束"}
          </Tag>
        );
      },
    },
    {
      title: "创建时间",
      dataIndex: "createTime",
      render: (createTime) => {
        return dayjs(createTime).format("YYYY-MM-DD HH:mm:ss");
      },
    },
    {
      title: "操作",
      key: "action",
      render: (index, record) => (
        <Space size="middle">
          <a onClick={async()=>{
              
          }}>修改状态</a>
        </Space>
      ),
    },
  ];

  return (
    <div>
      <Table<DataType> columns={columns} dataSource={datalist} rowKey={"id"} />;
    </div>
  );
};

export default Typelist;
